package com.hks360.car_treasure.trail.presenter;

import android.content.Context;

import com.hks360.car_treasure.model.JourneyLocation;
import com.hks360.car_treasure.trail.model.TrailModel;
import com.hks360.car_treasure.trail.model.TrailModelImpl;
import com.hks360.car_treasure.trail.view.TrailView;
import com.hks360.car_treasure.util.LogUtil;

import java.util.List;

public class TrailPresenterImpl implements TrailPresenter {
    private TrailModel equipmentModel;
    private TrailView locationView;

    public TrailPresenterImpl(Context context, TrailView locationView) {
        this.equipmentModel = new TrailModelImpl(context);
        this.locationView = locationView;
    }

    @Override
    public void readJourneyLocation(int what, String startTime, String endTime) {
        TrailModelImpl.JourneyListener listener  = new TrailModelImpl.JourneyListener() {
            @Override
            public void onSuccess(int what, List<JourneyLocation> journeyLocations) {
                if (journeyLocations != null) {
                    locationView.readJourneyLocationSuccess(journeyLocations);
                } else {
                    locationView.readJourneyLocationFailed();
                }
            }
            @Override
            public void onFailed(int what) {
                locationView.readJourneyLocationFailed();
            }

            @Override
            public void onStart(int what) {
                locationView.showLoading();
            }

            @Override
            public void onFinish(int what) {
                locationView.hideLoading();
            }
        };
        equipmentModel.readJourneyLocation(what,locationView.getTboxId(),startTime, endTime,listener);
    }
}
